home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
pxewin.zip
/
BROWSE.CPP
< prev
next >
Wrap
Text File
|
1992-02-27
|
10KB
|
378 lines
// PXEWIN - (C) Copyright 1992 by Beam Engineering, INC.
// BROWSE.CPP //
// Contents ----------------------------------------------------------------
//
// This module contains members for the Browser class.
//
// End ---------------------------------------------------------------------
// External Reference Name for this Header ---------------------------------
#ifndef BROWSE_CPP
#define BROWSE_CPP
// End ---------------------------------------------------------------------
// Interface Dependencies --------------------------------------------------
#ifndef BROWSE_HPP
#include "browse.hpp"
#endif // BROWSE_HPP //
// End ---------------------------------------------------------------------
__link(RegWindow)
// member Browser //
Browser::Browser(PTWindowsObject AParent,int):TWindow(AParent,"")
{
my_display = NULL;
Scroller = NULL;
name = new char[MAXPATH];
// Set the X scroll position to it's default.
XScroll = 0;
// Enable the keyboard so the children can inherit this property
EnableKBHandler();
}
// Summary -----------------------------------------------------------------
//
// Creates a browser window for browsing a Paradox database.
//
// Parameters
//
// AParent. This would be the MDI frame window.
//
// The int is for the window count since each window object is put into
// a linked list.
//
// Functional Description
//
// 1. NULL out the display and scroller objects so they will not be
// deleted before they are created.
//
// 2. Create a new name buffer for the database name.
//
// 3. Set the horizontal scroll position to zero by default. If the
// window is to be constructed from a stream then this value will
// be changed when the reader is called.
//
// End ---------------------------------------------------------------------
// destructor Browser //
inline Browser::~Browser()
{
delete my_display;
my_display = NULL;
delete name;
name = NULL;
delete Scroller;
Scroller = NULL;
// Dispatch a message to the BrowserFrame that you have killed
// yourself.
SendMessage(Parent->HWindow,WM_CHKCHILD,0,0);
}
// Summary -----------------------------------------------------------------
//
// Delete database name and tell the BrowserFrame to check its children.
//
// End ---------------------------------------------------------------------
// member GetDB //
int Browser::GetDB()
{
strcpy(name,"*.db"); /* Construct a file mask for
the file dialog */
// Execute file dialog
if(GetApplication()->ExecDialog(
new TFileDialog(this,SD_FILEOPEN,
name)) == IDOK)
{
flag = EXISTS;
// Store a copy of the database name to the window header
Title = _fstrdup(name);
if(*Title == NULL)
flag = NOTEXISTS;
}
else
flag = NOTEXISTS;
// If database does not exist, NULL out db and return
if(flag == NOTEXISTS)
return flag;
// Get the display for the database setup.
my_display = new DBDISPLAY;
my_display->SetUp(this);
if(my_display->RetPXError() != PXSUCCESS)
flag = NOTEXISTS;
// Set up scroll bars.
Attr.Style |= WS_VSCROLL | WS_HSCROLL;
// Point the Scroller to the custom database scroller. Vertical
// scroll will be redifined.
Scroller = new PXScroller(this,8,15,80,60);
return flag;
}
// Summary -----------------------------------------------------------------
//
// Sets up the Browser for displaying a database.
//
// Return Value
//
// Returns flag which indicates whether the database exists of not.
//
// Functional Description
//
// 1. Construct a file name mask.
//
// 2. Call the File dialog box. If file exists, set flag to EXISTS.
// Save a copy of the file name to the Title of the window data member.
// If the Title is NULL or the file dialog does not return IDOK then
// set existance flag to NOTEXIST.
//
// 3. If flag is set to NOTEXIST, return to BrowserFrame.
//
// 4. Set up the database.
//
// 5. If an error occured in the set up, display the error, set the
// flag to NOTEXIST and return to the MDI.
//
// 6. Set the styles for the scroll bars and construct the Scroller.
//
// End ---------------------------------------------------------------------
// member SetupWindow //
void Browser::SetupWindow()
{
int sum; /* This is the accumulated
length of all the list
boxes */
TWindow::SetupWindow();
// You want to set the x scroller range depending on how many
// total characters you have in all the fields. The y
// scroller range is determined by how many records you have
// in the database.
my_display->my_table->NumRecs();
sum = my_display->RetSum();
Scroller->SetRange((int)(sum*my_display->RetCharWidth()/
Scroller->XUnit),my_display->EngDataPtr->num_recs - 1);
// Get the data from the database and fill up list boxes
// with it and select the first entrie.
my_display->FillBoxes(my_display->top_rec);
// If the value of XScroll is not zero, then do a ScrollBy. This is
// so you can set the initial position of the scroll to what has
// been saved on the desktop stream.
if(XScroll)
{
// Check and see if your still in field range first. Some
// one could have changed the database structure since you
// last saved the desktop.
if(XScroll > sum)
XScroll = sum;
Scroller->ScrollBy(XScroll,0);
}
}
// Summary -----------------------------------------------------------------
//
// Sets up browser window
//
// Parameters
//
// None.
//
// Return Value
//
// None.
//
// Description
//
// Calls TWindows set up. Sets the range on the scroll bar to
// conform with the database ranges and fills the list boxes with
// the data. If XScroll is not zero then a scroll position has been
// read off the stream so the scroller is set to that position. The
// DBDISPLAY class sets the vertical scroll position.
//
// End ---------------------------------------------------------------------
// member read of Browser //
inline Pvoid Browser::read(Ripstream)
{
return this;
}
// member write of Browser //
inline void Browser::write(Ropstream)
{
}
// member ReadChildren of Browser //
inline int Browser::ReadChildren(Ripstream is)
{
int error; /* Non-zero if error */
// Get the database name off the stream.
name = is.freadString();
// Get the window attribs off the stream
is >> (long)Attr.Style >> Attr.X >> Attr.Y >> Attr.W >> Attr.H;
// Construct a new display from the stream
is >> my_display;
// Save name to the window title
Title = _fstrdup(name);
// Set up the display. If display fails, bail out.
error = my_display->SetUp(this);
if(error)
return error;
// Point the Scroller to the custom database scroller. Vertical
// scroll will be redifined.
Scroller = new PXScroller(this,8,15,80,60);
// Initialize Scroller to correct position
Scroller->YPos = my_display->RetCurRec() - 1;
is >> XScroll;
return PXSUCCESS;
}
// Summary -----------------------------------------------------------------
//
// Child reads data off the stream.
//
// Parameters
//
// is. The input stream.
//
// Functional Description
//
// 1. Create a name buffer and read the string for the database name
// off the stream.
//
// 2. Read the window attributes from the stream.
//
// 3. Construct a new display from the stream.
//
// 4. The window Title is the name of the database.
//
// 5. Set the display up.
//
// 6. Make a scroller. Set the vertical scroll position to the current
// record. Set the horizontal scroll position.
//
// End ---------------------------------------------------------------------
// member WriteChildren of Browser //
inline void Browser::WriteChildren(Ropstream os)
{
os.fwriteString(name);
os << (long)Attr.Style << Attr.X << Attr.Y << Attr.W << Attr.H;
os << my_display;
os << Scroller->XPos;
}
// Summary -----------------------------------------------------------------
//
// Writes this child to the stream.
//
// Parameters
//
// os. This is the stream output.
//
// Functional Description
//
// 1. Write the name to the stream.
//
// 2. Save the window Attribs to the stream.
//
// 3. Save the display to the stream.
//
// 4. Save the current scroller position to the stream.
//
// End ---------------------------------------------------------------------
// member build of Browser //
PTStreamable Browser::build()
{
return new Browser(streamableInit);
}
TStreamableClass RegBrowser("Browser",Browser::build,
__DELTA(Browser));
// Description -------------------------------------------------------------
//
// When the streamable constructor is called, TStreamable dispatches
// the build member to construct the object. To do this, it must
// know where to find this member functions for the specific class.
// This is the reason for the stream registration.
//
// End ---------------------------------------------------------------------
// member SetScroller of Browser //
void Browser::SetScroller()
{
Scroller->YPos = my_display->RetCurRec() - 1;
Scroller->EndView();
}
// Summary -----------------------------------------------------------------
//
// Sets the scroller position to coorespond to the current position in
// the database. Sets the YPos to the currently selected record and
// calls EndView to update the scroll position.
//
// End ---------------------------------------------------------------------
#endif // BROWSE_CPP //